package com.li.youhappygo.exception;

import com.li.youhappygo.model.vo.common.Result;
import com.li.youhappygo.model.vo.common.ResultCode;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(GlobalException.class)
    @ResponseBody
    public Result globalExceptionHandler(GlobalException e) {
        e.printStackTrace();
        if(e.getCode() == ResultCode.DATA_ERROR.getCode()){
            return Result.build(null, e.getCode(), e.getMessage());
        }
        return Result.build(null, ResultCode.SYSTEM_ERROR);
    }
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result exceptionHandler(Exception e) {
        e.printStackTrace();
        return Result.build(null, ResultCode.SYSTEM_ERROR);
    }
}
